< previous page page_182 next page >

Page 182
9f31265bb40b592b1929e18a47ab28e5.gif
   Dim strEmp As String

   strEmp = "My Last Name is " & strLast
   strEmp = strEmp & " and my first name is " & strFirst

   EmployeeDisplay = strEmp
End Sub
In this version of the EmployeeDisplay procedure, the first and last names of the employee are passed in. This makes this procedure much more reusable its not reliant on the txtFirst and txtLast text boxes being created on the form. Any value from any text boxes can be passed in, no matter what its name is.
Calling Procedures with Parameters
Now that weve made this procedure accept these arguments, we need to call it in a different manner. First, well pass each parameter in the order they are declared in the function. Second, well separate each parameter with a comma. Because these parameters are declared as strings, the string values must be enclosed in double quotes. Well use a slightly different syntax when calling a procedure using the Call keyword versus not using the Call keyword. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   EmployeeDisplay "Bill", "Gates"
   Call EmployeeDisplay("Michael", "Gilbert")
End Sub
Notice that when the Call keyword isnt used, the parameters arent placed in parentheses. However, if you do use the Call keyword, youll need to add parentheses around the two parameters.
The preceding example uses hard-coded strings as the parameters to the EmployeeDisplay procedure. However, you could also pass in the values from the text boxes on the form. Heres how:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   EmployeeDisplay txtFirst.Text, txtLast.Text
   Call EmployeeDisplay(txtFirst.Text, txtLast.Text)
End Sub

 
< previous page page_182 next page >

If you like this book, buy it!